{
    "cells": [
        {
            "source": [
                "# Prerequisites\n",
                "\n",
                "### pip install ipysheet"
            ],
            "cell_type": "markdown",
            "metadata": {}
        },
        {
            "cell_type": "code",
            "execution_count": 38,
            "metadata": {
                "scrolled": true
            },
            "outputs": [],
            "source": [
                "from ipywidgets import FloatSlider, IntSlider, Image\n",
                "import ipysheet"
            ]
        },
        {
            "source": [
                "# 1. Test Rendering a Sheet"
            ],
            "cell_type": "markdown",
            "metadata": {}
        },
        {
            "cell_type": "code",
            "execution_count": 39,
            "metadata": {},
            "outputs": [],
            "source": [
                "sheet = ipysheet.sheet(rows=3, columns=4)\n",
                "cell1 = ipysheet.cell(0, 0, 'Hello')\n",
                "cell2 = ipysheet.cell(2, 0, 'World')\n",
                "cell_value = ipysheet.cell(2,2, 42.)\n",
                "sheet"
            ]
        },
        {
            "source": [
                "# 2. Test Searching a Sheet (interact with textbox in a different cell)"
            ],
            "cell_type": "markdown",
            "metadata": {}
        },
        {
            "cell_type": "code",
            "execution_count": 40,
            "metadata": {},
            "outputs": [],
            "source": [
                "\n",
                "import numpy as np\n",
                "import pandas as pd\n",
                "from ipysheet import from_dataframe\n",
                "from ipywidgets import Text, VBox, link\n",
                "\n",
                "df = pd.DataFrame({'A': 1.,\n",
                "                   'B': pd.Timestamp('20130102'),\n",
                "                   'C': pd.Series(1, index=list(range(4)), dtype='float32'),\n",
                "                   'D': np.array([False, True, False, False], dtype='bool'),\n",
                "                   'E': pd.Categorical([\"test\", \"train\", \"test\", \"train\"]),\n",
                "                   'F': 'foo'})\n",
                "\n",
                "df.loc[[0, 2], ['B']] = np.nan\n",
                "\n",
                "\n",
                "sheet2 = from_dataframe(df)\n",
                "\n",
                "search_box = Text(description='Search:')\n",
                "link((search_box, 'value'), (sheet2, 'search_token'))"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": 41,
            "metadata": {},
            "outputs": [],
            "source": [
                "search_box"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": 42,
            "metadata": {},
            "outputs": [],
            "source": [
                "sheet2"
            ]
        },
        {
            "source": [
                "# 3. Test calculations (slider update cell value via python code)"
            ],
            "cell_type": "markdown",
            "metadata": {}
        },
        {
            "cell_type": "code",
            "execution_count": 51,
            "metadata": {},
            "outputs": [],
            "source": [
                "from ipywidgets import FloatSlider, IntSlider, Image, IntText, link\n",
                "import ipysheet\n",
                "\n",
                "slider = IntSlider(description=\"Continuous\", continuous_update=True)\n",
                "textbox = IntText(description=\"Continuous\", continuous_update=True)\n",
                "\n",
                "link((slider, 'value'), (textbox, 'value'))"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": 52,
            "metadata": {},
            "outputs": [],
            "source": [
                "slider"
            ]
        },
        {
            "source": [
                "* Typing value into textbox will move slider\n",
                "* The value in cell will also get updated"
            ],
            "cell_type": "markdown",
            "metadata": {}
        },
        {
            "cell_type": "code",
            "execution_count": 53,
            "metadata": {},
            "outputs": [],
            "source": [
                "textbox"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": 57,
            "metadata": {},
            "outputs": [],
            "source": [
                "sheet = ipysheet.sheet()\n",
                "\n",
                "cell1 = ipysheet.cell(0, 0, slider, style={'min-width': '150px'})\n",
                "cell3 = ipysheet.cell(2, 2, 50.)\n",
                "cell_sum = ipysheet.cell(3, 2, 50.)\n",
                "\n",
                "@ipysheet.calculation(inputs=[(cell1, 'value'), cell3], output=cell_sum)\n",
                "def calculate(a, b):\n",
                "    return a + b\n",
                "\n",
                "sheet"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": null,
            "metadata": {},
            "outputs": [],
            "source": []
        }
    ],
    "metadata": {
        "celltoolbar": "Attachments",
        "file_extension": ".py",
        "language_info": {
            "codemirror_mode": {
                "name": "ipython",
                "version": 3
            },
            "file_extension": ".py",
            "mimetype": "text/x-python",
            "name": "python",
            "nbconvert_exporter": "python",
            "pygments_lexer": "ipython3",
            "version": "3.8.1-final"
        },
        "mimetype": "text/x-python",
        "name": "python",
        "npconvert_exporter": "python",
        "pygments_lexer": "ipython3",
        "toc": {
            "base_numbering": 1,
            "nav_menu": {},
            "number_sections": false,
            "sideBar": false,
            "skip_h1_title": false,
            "title_cell": "Table of Contents",
            "title_sidebar": "Contents",
            "toc_cell": false,
            "toc_position": {},
            "toc_section_display": false,
            "toc_window_display": false
        },
        "version": 3
    },
    "nbformat": 4,
    "nbformat_minor": 2
}
